import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../views/Login.vue'
// import Home from '../views/Home.vue'
// import Welcome from '../views/Welcome.vue'
// import Users from '../views/users/Users.vue'
// import Roles from '../views/rights/Roles.vue'
// import Rights from '../views/rights/Rights.vue'
// import Categories from '../views/goods/Categories.vue'
// import Goods from '../views/goods/Goods.vue'
// import Params from '../views/goods/Params.vue'
// import AddGood from '../views/goods/AddGood.vue'
// import Orders from '../views/orders/Orders.vue'
// import Reports from '../views/reports/Reports.vue'
const Login = () => import(/* webpackChunkName: "login" */ '../views/Login.vue')
const Home = () => import(/* webpackChunkName: "Home" */ '../views/Home.vue')
const Welcome = () => import(/* webpackChunkName: "Home" */ '../views/Welcome.vue')
const Users = () => import(/* webpackChunkName: "Users" */ '../views/users/Users.vue')
const Roles = () => import(/* webpackChunkName: "Rights" */ '../views/rights/Roles.vue')
const Rights = () => import(/* webpackChunkName: "Rights" */ '../views/rights/Rights.vue')
const Categories = () => import(/* webpackChunkName: "Goods" */ '../views/goods/Categories.vue')
const Goods = () => import(/* webpackChunkName: "Goods" */ '../views/goods/Goods.vue')
const Params = () => import(/* webpackChunkName: "Goods" */ '../views/goods/Params.vue')
const AddGood = () => import(/* webpackChunkName: "Goods" */ '../views/goods/AddGood.vue')
const Orders = () => import(/* webpackChunkName: "Orders" */ '../views/orders/Orders.vue')
const Reports = () => import(/* webpackChunkName: "Reports" */ '../views/reports/Reports.vue')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    redirect: '/welcome',
    component: Home,
    children: [
      {
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/users',
        component: Users
      },
      {
        path: '/roles',
        component: Roles
      },
      {
        path: '/rights',
        component: Rights
      },
      {
        path: '/categories',
        component: Categories
      },
      {
        path: '/goods',
        component: Goods
      },
      {
        path: '/params',
        component: Params
      },
      {
        path: '/goods/update/:userId',
        component: AddGood,
        props: true
      },
      {
        path: '/orders',
        component: Orders
      },
      {
        path: '/reports',
        component: Reports
      }
    ]
  }

]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  sessionStorage.getItem('token') ? next() : to.path === '/login' ? next() : next({ path: '/login' })
})

export default router
